package com.hiultra.archive.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.hiultra.common.annotation.Log;
import com.hiultra.common.core.controller.BaseController;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.enums.BusinessType;
import com.hiultra.archive.domain.ArchiveDesUser;
import com.hiultra.archive.service.IArchiveDesUserService;
import com.hiultra.common.utils.poi.ExcelUtil;
import com.hiultra.common.core.page.TableDataInfo;

/**
 * 销毁用户Controller
 *
 * @author paidaxing
 * @date 2024-08-03
 */
@RestController
@RequestMapping("/archive/ArchiveDesUser")
public class ArchiveDesUserController extends BaseController {
    @Autowired
    private IArchiveDesUserService archiveDesUserService;

    /**
     * 查询销毁用户列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(ArchiveDesUser archiveDesUser) {
        startPage();
        List<ArchiveDesUser> list = archiveDesUserService.selectArchiveDesUserList(archiveDesUser);
        return getDataTable(list);
    }

    /**
     * 导出销毁用户列表
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesUser:export')")
    @Log(title = "销毁用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ArchiveDesUser archiveDesUser) {
        List<ArchiveDesUser> list = archiveDesUserService.selectArchiveDesUserList(archiveDesUser);
        ExcelUtil<ArchiveDesUser> util = new ExcelUtil<ArchiveDesUser>(ArchiveDesUser.class);
        util.exportExcel(response, list, "销毁用户数据");
    }

    /**
     * 获取销毁用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(archiveDesUserService.selectArchiveDesUserById(id));
    }

    /**
     * 新增销毁用户
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesUser:add')")
    @Log(title = "销毁用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ArchiveDesUser archiveDesUser) {
        return toAjax(archiveDesUserService.insertArchiveDesUser(archiveDesUser));
    }

    /**
     * 修改销毁用户
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesUser:edit')")
    @Log(title = "销毁用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ArchiveDesUser archiveDesUser) {
        return toAjax(archiveDesUserService.updateArchiveDesUser(archiveDesUser));
    }

    /**
     * 删除销毁用户
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesUser:remove')")
    @Log(title = "销毁用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(archiveDesUserService.deleteArchiveDesUserByIds(ids));
    }

    /**
     * 批量修改销毁用户状态
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesUser:updateArchiveDesUserTaskStatus')")
    @Log(title = "销毁用户", businessType = BusinessType.DELETE)
    @PostMapping("/updateArchiveDesUserTaskStatus")
    public AjaxResult updateArchiveDesUserTaskStatus(@RequestParam("ids") String[] ids,@RequestParam("desStatus")String desStatus) {
        return toAjax(archiveDesUserService.updateArchiveDesUserTaskStatus(desStatus, ids));
    }

    /**
     * 根据任务id查询销毁用户详情
     */
    @PreAuthorize("@ss.hasPermi('archive:ArchiveDesUser:query')")
    @GetMapping(value = "/selectDesUserByTaskId/{taskId}")
    public AjaxResult selectDesUserByTaskId(@PathVariable("taskId") String taskId) {
        return AjaxResult.success(archiveDesUserService.selectArchiveDesUserByTaskId(taskId));
    }
}
